﻿using System;
using System.Windows.Forms;
using System.IO;

namespace Upgrade
{
    public partial class MainForm : Form
    {
        const String DataCookieone = "Slist_Data_V.1.0";
        const String DataCookietwo = "Slist_Dat_V.1.0";

        public MainForm()
        {
            InitializeComponent();
        }

        private void MainForm_Load(object sender, EventArgs e)
        {
            try
            {
                ChooseImportFile.ShowDialog();
                File.Copy(ChooseImportFile.FileName, "DATA.tmp");
                StreamReader reader = new StreamReader(ChooseImportFile.FileName);
                StreamWriter writer = new StreamWriter("CurrentFile.tmp");
                if(reader.ReadLine()==DataCookieone){
                    while (!reader.EndOfStream)
                    {
                        writer.WriteLine(DataCookietwo);
                        String value = reader.ReadLine();
                        if (value == "-")
                        {
                            writer.WriteLine("?END");
                        }
                        else
                        {
                            writer.WriteLine(value);
                        }
                        writer.Close();
                    }
                }
                File.Delete("DATA.tmp");
            }
            catch
            {
                MessageBox.Show("An Error Occured! No files have been lost.");
                File.Copy("DATA.tmp", ChooseImportFile.FileName);
                File.Delete("DATA.tmp");
            }
        }
    }
}
